package com.zhihaoliang.map.home

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import com.zhihaoliang.map.R
import kotlinx.coroutines.delay

/**
 * @author 支豪亮
 * @date 2023/1/16 10:01
 */

private const val SplashWaitTime:Long = 2000

/**
 * 数据加载中的Loading
 */
@Composable
fun LandingScreen(modifier: Modifier = Modifier,onTimeout: () -> Unit){
    Box(modifier = modifier.fillMaxSize(), contentAlignment = Alignment.Center){
        // onTimeout 在附带效应正在进行时发生更改，不能保证在效应结束时会调用最后一个 onTimeout。
        // 如需通过捕获和更新到新值来保证这一点，请使用 rememberUpdatedState API
        val currentOnTimeout by rememberUpdatedState(onTimeout)

        LaunchedEffect(true){
            delay(SplashWaitTime)
            currentOnTimeout()
        }

        Image(painter = painterResource(id = R.drawable.ic_crane_drawer), contentDescription = null)
    }
}

@Composable
@Preview
fun LandingScreenPreview(){
    LandingScreen(){}
}